<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="../../commons/taglibs.jsp"%>
<%@ include file="../../commons/list.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta charset="utf-8">
  <title>用户管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <style type="text/css">
  	input{
  		width: 200px;
  		display: inline;
  	}
  </style>
</head>

<body>
 <div>
	<div style="padding: 50px;padding-top: 50px">
		<form class="layui-form layui-form-pane"  action="">
		<input type="hidden" id='entityId' name='entityId' value="${sysUser.id }">
		  <div class="layui-form-item" style="width: 85%;padding-left: 60px">
		    <label class="layui-form-label">登录名</label>
		     <div class="layui-input-block">
		      <input type="text" name="userid" value="${sysUser.userid}" required  lay-verify="required" placeholder="请输入登录名" autocomplete="off" class="layui-input">
		    </div>
		  </div>
		  
		  <div class="layui-form-item" style="width: 85%;padding-left: 60px">
		     <label class="layui-form-label">用户名</label>
		    <div class="layui-input-block">
		      <input type="text" name="username" value="${sysUser.username }" required  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
		    </div>
		  </div>
		  
		  <div class="layui-form-item" style="width: 85%;padding-left: 60px">
			<label class="layui-form-label">角色</label>
			<div class="layui-input-block" id="tag_ids2">
  
      		</div>
	  </div>  
		  
		  <div class="layui-form-item" style="width: 85%;padding-left: 150px;padding-top: 30px">
		    <div class="layui-input-block">
		      <button class="layui-btn" id='tjsub' lay-submit lay-filter="formDemo">立即提交</button>
		      <a class="layui-btn" onclick="closeWindow()"><i class="layui-icon">&#xe65c;</i>返回</a>
		    </div>
		  </div>
		</form>
	</div>
 </div> 

<script>

  var tagData = ${allRoles};    

  layui.config({
	 
  }).extend({
    selectN: '<%=basePath%>common/plugins/layui_extends/selectN',
    selectM: '<%=basePath%>common/plugins/layui_extends/selectM'
  }).use(['layer','form','jquery','selectN','selectM'],function(){
    $ = layui.jquery;	
    var form = layui.form
    ,selectN = layui.selectN
    ,selectM = layui.selectM;
         
    //多选标签-所有配置
    var tagIns2 = selectM({
      //元素容器【必填】
      elem: '#tag_ids2'
      ,verify:"required"
      //候选数据【必填】
      ,data: tagData
      //默认值
      ,selected: ${roleIds} 			
      
      //最多选中个数，默认5
		,max : 6
	    
		//input的name 不设置与选择器相同(去#.)
		,name: 'roleids'
		
		//值的分隔符
		,delimiter: ','
	    
		//候选项数据的键名
		,field: {idName:'id',titleName:'name'}
    });
			
   //监听提交
  form.on('submit(formDemo)', function(data){
	  //提交成功后禁用按钮
	  $("#tjsub").css("pointer-events","none"); 
	  $.post('<%=basePath%>controller/sysUser/save',data.field,function(data){
		  if(data == '1'){
			  $("#tjsub").css("pointer-events","auto");
			  layer.msg('提交失败', {time:1000});
		  }
		  if(data == '0'){
			  layer.msg('提交成功', {time:1000});
			  setTimeout("layer.closeAll()",1000);
			  //调用刷新页面
			  setTimeout("parent.location.reload()",2000);
			  
		  }
		  if(data == '2'){
			  $("#tjsub").css("pointer-events","auto");
			  layer.msg('已存在该登录名，请换一个', {time:2000});
		  }
	  })
    return false;
  });
     
		
	//监听重置按钮
	$('form').find(':reset').click(function(){
		$('form')[0].reset();
	     tagIns2.set();//默认值
		return false;
	});
    
 });
//返回按钮事件
  function closeWindow(){
          var index = parent.layer.getFrameIndex(window.name);
  		parent.layer.close(index);
  } 
</script>
</body>
</html>
